package com.wxlsoft.excel.extract;

import java.util.LinkedList;
import java.util.List;

import javax.swing.JProgressBar;

import com.alibaba.excel.context.AnalysisContext;
import com.wxlsoft.excel.core.AbstractSheetListener;
import com.wxlsoft.excel.extract.InterfaceManifest.SheetInput;
import com.wxlsoft.excel.extract.InterfaceManifest.SheetOutput;

/**
 * 模板的读取类
 * @author wangxiaoliang
 */
public class SheetInputListener extends AbstractSheetListener<SheetInput> {

	private final List<SheetOutput> datas;
	
	private final SheetDataCollector collector;
	
	public SheetInputListener(String sheetName, JProgressBar progress, 
			final SheetDataCollector collector) {
		super(sheetName, progress);
		this.datas = new LinkedList<>();
		this.collector = collector;
	}
	
	@Override
    public void invoke(SheetInput data, AnalysisContext context) {
		if (data.isNotEmpty())
			datas.add(new SheetOutput(data.getField(), data.getFieldName()));
    }

    @Override
    public void doAfter(AnalysisContext context) {
        collector.addAll(datas);
    }

}
